#ifndef YOOHOO_XMPPIM_STANZATASK_H
#define YOOHOO_XMPPIM_STANZATASK_H

#include "xmppim/export.h"

#include <QtCore/QString>
#include <QtCore/QList>

namespace yoohoo_xmppcore {

class JabberId;
class Stanza;
class StanzaError;

}

namespace yoohoo_xmppim {

class XmppClient;

using namespace yoohoo_xmppcore;

class YOOHOO_XMPPIM_EXPORT StanzaTask {
public:
	StanzaTask(bool autoDelete = true, JabberId* to = 0);
	~StanzaTask();
	void setAutoDelete(bool autoDelete);
	bool autoDelete() const;
	void setTo(const JabberId* to);
	const JabberId* to() const;
	virtual bool process(XmppClient* xmppClient, Stanza* stanza) = 0;
	virtual bool processError(StanzaError* error, bool& errorHandled);
	virtual bool matches(XmppClient* xmppClient, Stanza* stanza);
	virtual bool matches(XmppClient* xmppClient, StanzaError* error);
	void setTaskId(QString taskId);
	QString taskId();

protected:
	bool _autoDelete;
	JabberId* _to;

private:
	QString _taskId;
};

class YOOHOO_XMPPIM_EXPORT AbstractStanzaTask : public StanzaTask {
public:
	AbstractStanzaTask(bool autoDelete = true, JabberId* to = 0);
	virtual bool process(XmppClient* xmppClient, Stanza* stanza);

protected:
	virtual void begin(XmppClient* xmppClient) = 0;
	virtual bool processResponse(XmppClient* xmppClient, Stanza* stanza) = 0;
};

class YOOHOO_XMPPIM_EXPORT SequentialStanzaTask : public StanzaTask {
public:
	SequentialStanzaTask(bool autoDelete = true);
	~SequentialStanzaTask();
	bool process(XmppClient* xmppClient, Stanza* stanza);
	bool processError(StanzaError* error, bool& errorHandled);
	SequentialStanzaTask* appendTask(StanzaTask* task);

private:
	QList<StanzaTask*> _stanzaTasks;
};

}

#endif
